package com.shyroke.daydayzhuanweb.controller;

import com.shyroke.daydayzhuanapi.entity.ProjectEntity;
import com.shyroke.daydayzhuandao.respository.ProjectRepository;
import com.shyroke.daydayzhuansvc.util.UserUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 类名 ：网赚资讯controller
 * 用法 ：
 * 创建人 ： shyroke
 * 时间：2018/12/9 17:56
 */
@Controller
@RequestMapping(value = "news")
public class NewController {

    @Autowired
    private ProjectRepository projectRepository;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 跳转到网赚资讯首页
     * @return
     */
    @GetMapping(value = "/index/{id}")
    public ModelAndView index(ModelAndView model, @PathVariable("id")Integer typeId){

        //1、根据typeid到project_type表搜索该type下有多少个project
        List<ProjectEntity> projectList = projectRepository.findByTypeIdOrderByCreateTimeDesc(typeId);

        model.addObject("projectList",projectList);

        model = UserUtils.getMenuList(model,typeId);
        model.setViewName("news/index");
        return model;
    }


}
